<!--
 * @Description:
 * @Autor: 刘诗文
 * @Date: 2020-12-07 13:21:36
 * @LastEditors: 马毅
 * @LastEditTime: 2021-03-26 12:34:42
-->
<template>
  <div>
    <!--    <FormPanel ref="formPanel" :list="formList" :cols="3" :labelWidth="130" :formType="type" :isSubmitBtn="false" />-->
    <FilterTable
      ref="table"
      height="500"
      selectionType="single"
      :columns="columns"
      :datakey="'records'"
      :fetchapi="fetchApi"
      :params="fetchParams"
      columnsRef="potentialInfolsw"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="onRowSelectChange"
      :is-select-column="false"
    >
    </FilterTable>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { isFormEmpty, notifyAction, camelCaseObject } from '@/utils';
import { getPotentialInfo } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { getAllUser } from '@/api/customerRepair/afterSaleVisit/resultEntry';
import Cookies from 'js-cookie';
import { getChexSelectTable, getCheModelSelectTable } from '@/api/repair/repairReception/customer/brand.js';
export default {
  name: 'potentialInfo',
  mixins: [dictionary],
  props: ['type', 'customerInfo'],
  data() {
    this.selectedData = null;
    this.BaseTable = null;
    return {
      // formList: this.createFromList(),
      columns: this.createTableColumns(),
      fetchApi: getPotentialInfo,
      fetchParams: { xhrAbort: true },
      userList: []
    };
  },
  watch: {
    customerInfo(val) {
      this.checkChangeHandle();
    }
  },
  mounted() {
    this.BaseTable = this.$refs.table;
    this.getAllUser();
    this.getCode();
  },
  methods: {
    // createFromList() {
    //   return [
    //     {
    //       type: 'BREAK_SPACE',
    //       label: '潜客信息'
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '潜客编号',
    //       fieldName: 'a1',
    //       initialValue: ''
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '意向车系',
    //       fieldName: 'a2',
    //       initialValue: ''
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '意向车型',
    //       fieldName: 'a3',
    //       initialValue: ''
    //     },
    //     {
    //       type: 'SELECT',
    //       label: '是否已成交',
    //       fieldName: 'a4',
    //       initialValue: '',
    //       itemList: this.createDictList(1004)
    //     }
    //   ];
    // },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '潜客编号',
          dataIndex: 'potentialCustomerNo',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '潜客姓名',
          dataIndex: 'customerName',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '联系人电话',
          dataIndex: 'contactorMobile',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '联系人手机',
          dataIndex: 'contactorPhone',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '潜客一级来源',
          dataIndex: 'clueSourceFirst',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '潜客二级来源',
          dataIndex: 'clueSourceSecond',
          width: 120,
          showOverFlowTip: true
        },
        // {
        //   title: '潜客二级来源',
        //   dataIndex: 'clueSourceSecond',
        //   width: 120,
        //   showOverFlowTip: true
        // },
        {
          title: '跟进前级别',
          dataIndex: 'contactBeforeLevel',
          width: 120,
          showOverFlowTip: true,
          render: props => {
            return <span>{this.createDictText(props.row.contactBeforeLevel, 1519)}</span>;
          }
        },
        {
          title: '跟进后级别',
          dataIndex: 'factIntentLevel',
          width: 120,
          showOverFlowTip: true,
          render: props => {
            return <span>{this.createDictText(props.row.factIntentLevel, 1519)}</span>;
          }
        },
        {
          title: '跟进人',
          dataIndex: 'contactBy',
          width: 120,
          showOverFlowTip: true,
          render: props => {
            return <span>{this.getText('user', props.row.contactBy)}</span>;
          }
        },
        {
          title: '跟进时间',
          dataIndex: 'trackAt',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '意向车系',
          dataIndex: 'inteCarSeries',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '意向车型',
          dataIndex: 'inteCarType',
          width: 120,
          showOverFlowTip: true
        },
        {
          title: '是否已成交',
          dataIndex: 'isDeal',
          filterType: 'check',
          dictItems: this.createDictList('1004')
        },
        {
          title: '备注',
          dataIndex: 'remark',
          width: 120,
          showOverFlowTip: true
        }
      ];
    },
    onRowSelectChange(row) {
      if (!row.length) {
        this.selectedData = null;
      } else {
        this.selectedData = row[0];
      }
    },
    // 获取潜客记录
    async checkChangeHandle() {
      this.BaseTable.START_LOADING();
      if (this.customerInfo && !isFormEmpty(this.customerInfo.mobile)) {
        this.fetchParams = { mobile: this.customerInfo.mobile, userId: Cookies.get('userId') };
      }
      this.BaseTable.STOP_LOADING();
    },
    // 所有用户
    async getAllUser() {
      const res = await getAllUser();
      if (res.resultCode === 200) {
        if (res.errMsg) {
          notifyAction(res.errMsg, 'error');
        } else {
          this.userList = res.data.map(x => ({ value: x.userId + '', text: x.employeeName }));
        }
      }
    },
    async getCode() {
      let seriesRes = await getChexSelectTable();
      let modelRes = await getCheModelSelectTable();
      if (seriesRes.resultCode == 200) {
        this.columns.find(y => y.dataIndex == 'inteCarSeries').dictItems = seriesRes.data.map(x => ({ text: x.seriesName, value: x.seriesId }));
      }
      if (modelRes.resultCode == 200) {
        this.columns.find(y => y.dataIndex == 'inteCarType').dictItems = modelRes.data.map(x => ({ text: x.modelName, value: x.modelId }));
      }
    },
    // 人名字典值转换
    getText(type, val) {
      if (type === 'user') {
        return this.userList.find(x => x.value === val) ? this.userList.find(x => x.value === val).text : '';
      }
    }
  }
};
</script>
<style lang="less" scoped></style>
